package handler

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"internal/api/logic/qrcodes"
	"net/http"
)

// 秘钥开头
const pSecretKey string = "SignedQrcode"

func GenerateQRCode(c *gin.Context) {
	content := c.Query("content")
	// 获取哈希可以参数
	HashKey, _ := qrcodes.GetHashKey(pSecretKey)
	SignIn := fmt.Sprintf("http://82.156.87.105:18890/account/signin?expireTimeKey=%s", HashKey)
	// 从请求中获取content参数
	if content == "" {
		content = SignIn
	}
	img, err := qrcodes.SingedQrcode(content)
	if err != nil {
		c.JSON(http.StatusInternalServerError, gin.H{
			"code": -1,
			"msg":  err.Error(),
		})
	}
	c.Data(http.StatusOK, "image/png", img)
}
